﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OOAD_Project_Engine.Application.Services;
using OOAD_Project_Engine.Foundation.Interfaces;
using OOAD_Project_Engine.Domain.Entities;

namespace OOAD_Project_Editor.Domain.ManageSceneActions
{
    [Action(ActionType = EActionType.DuplicateEntity)]
    class DuplicateEntityAction : ManageSceneAction
    {
        IEntity entityPrototype;
        public string name { get; private set; }
        public IEntity NewEntity { get; private set; }
        public DuplicateEntityAction(ISceneService scene, string _name, IEntity prototype)
            : base(scene)
        {
            name = _name;
            entityPrototype = prototype;
        }

        public override void DoAction()
        {
            ICollection<IEntityComponent> entityComponents = entityPrototype;
            IEntityComponent[] components = new IEntityComponent[entityComponents.Count];
            int i = 0;
            foreach (IEntityComponent c in entityComponents)
            {
                components[i] = c.Clone() as IEntityComponent;
                i++;
            }
            NewEntity = Scene.Factory.Create<Entity>(name, components);
        }
    }
}
